//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "adminActions\fn_unjail.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_params","_caller_name","_caller_uid","_player_uid","_player_name","_player_info","_action","_authorized","_player","_player_id","_counter","_player_pos"];
PARAMS_3(_params,_caller_name,_caller_uid);

_authorized = _params select 0;
_action = _params select 1;
_player = _params select 2;
_player_uid = _params select 3;
_player_name = _params select 4;

if (isServer) then {
	_player_info = [];
	_index = GVAR(PlayerIndex) find _player_uid;
	if (_index >= 0) then {
		_player_info = GVAR(PlayerInfo) select _index;
	};
	TLOG_1("UNJAIL",_player_info);
	if (count _player_info > 0) then {
		// _player_info set [0, _name];	// Player name at login
		// _player_info set [1, _uid];		// Player UID
		// _player_info set [2, _id];		// Player DirectPlay ID at login
		// _player_info set [3, MSO_AA_PLAYER_ID_COUNT]; // Player ID at login
		// _player_info set [4, time];		// Player first login time
		// _player_info set [5, getPos player];// Initial Position
		// _player_info set [6, time];		// Player last login time
		// _player_info set [7, 0];		// Player jails
		// _player_info set [8, 0];		// Player kicks
		// _player_info set [9, 0];		// Player bans
		// _player_info set [10, 0];		// Player teleports
		// _player_info set [11, 0];		// Player vehicle crashes
		
		_player_id = (_player_info select 3);
		_player_name = (_player_info select 0);
		_player_pos = (_player_info select 5);
		
		_player = objNull;
		{ if (getPlayerUID _x == _player_uid) exitWith { _player = _x; };
		} foreach playableUnits;
		
		if (!isNull _player) then {
			PSETVARP(QGVAR(IS_PLAYER_JAILED),false);
		} else {
			ERROR_1("Player Not Found",_player_uid);
		};
	} else {
		ERROR_1("Missing Player Info",_player_uid);
	};
};
if (!isDedicated) then {
	if (_player_uid == getPlayerUID player) then {
		PSETVARP(QGVAR(IS_PLAYER_JAILED),false);
	} else {
		hint format[localize "STR_MSO_AA_UNJAILED", _player_name, _player_uid];
	};
};

TRACE("End");
TMFPROFILERSTOP;
